﻿@{
    Layout = "~/Views/Shared/_level2.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
    }
}
<title>销售应用-待发货订单</title>
<link href="/SiteUI/Sale/share.css" rel="stylesheet" />
<link href="/SiteUI/Sale/Delivery.css" rel="stylesheet" />
<link href="/SiteUI/bootstrap-datepicker3.css" rel="stylesheet" />
@section contentnavi{
<div id="appTitle">
    销售应用
</div>
<ul id="slideNavi">
    <li><a class="Lite" href="/Sale/Quotation"><i class="icon-zhangwuxinxi"></i>报&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价<i class="icon-navigatenext arrow-go"></i></a></li>
    <li class="naviGroup">
        销售订单
        <a class="Lite" href="/Sale/MyOrders"><i class="icon-svgorderred"></i>我的订单<i class="icon-navigatenext arrow-go"></i></a>
        <a class="Lite" href="/Sale/Orders"><i class="icon-svgorderred"></i>部门订单<i class="icon-navigatenext arrow-go"></i></a>
    </li>
    <li class="naviGroup">
        发货管理
        <a class="Lite" href="/Sale/WaitDelivery"><i class="icon-svgorderred"></i>待&nbsp;&nbsp;发&nbsp;&nbsp;货<i class="icon-navigatenext arrow-go"></i></a>
        <a class="Lite" href="/Sale/Delivery"><i class="icon-localshipping"></i>发货记录<i class="icon-navigatenext arrow-go"></i></a>
    </li>
</ul>
}
<div class="col-lg-5 col-lg-offset-6 searchboxWraper">
    <!--搜索框组件容器-->
</div>
<div class="col-lg-10 col-lg-offset-1" id="ToDlvOrders">
    <div class="row" id="lstOrders">
        <div class="col-lg-12 head">
            <h4>待发货订单</h4>
            <span class="cnd-status" status=''>全部</span>
            <span class="more-filter" id="more-filter">更多筛选条件</span>

        </div>
        <form class="col-lg-12 more-filter-box" id="more-filter-box">
            <button class="more-filter-close" id="more-filter-close" type="button"><i class="soicon icon-highlightremove"></i></button>
            <div class="filter-item">
                <span class="label">订单编号：</span>
                <label class="input-box col-lg-12"><input class="input" type="text" name="client"></label>
            </div>
            <div class="filter-item">
                <span class="label">客&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;户：</span>
                <label class="input-box col-lg-12"><input class="input" type="text" name="client"></label>
            </div>
            <div class="filter-item">
                <span class="label">订货日期：</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="orderDateStart"></label>
                <span class="col-lg-2">至</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="orderDateEnd"></label>
            </div>
            <div class="filter-item">
                <span class="label">交货日期：</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="dlvDateStart"></label>
                <span class="col-lg-2">至</span>
                <label class="input-box col-lg-5 date-picker"><input class="input" type="text" name="dlvDateEnd"></label>
            </div>
            <div class="filter-item">
                <button class="filter-search button">筛&nbsp;&nbsp;选</button>
            </div>
        </form>
        <div class="col-lg-12" id="dlv-lstOrders">

        </div>

        <div class="col-lg-12" id="sal-lstOrders-Paging"></div>
    </div>
</div>


<!--发货用订单列表模板-->
<script id="tplOrderItem" type="text/html">
    <div class="row noItem" >
        <div class="col-lg-1 no-row-head">
            <img src='{{d.client_logo}}' />  <!--买方Logo-->
        </div>
        <div class="col-lg-11 no-row-body">
            <div class="row no-headline">
                <div class="col-lg-4 no-tradeno">
                    <span>交易编号：</span><span>{{d.idstr}}</span>
                </div>
                <div class="col-lg-5 no-client">
                    <span><i class="soicon icon-004office"></i>&nbsp;{{(d.client_realname)?d.client_realname:d.invoiceheading}}</span>
                </div>
                <div class="col-lg-3">
                    
                    <a class="LinkTo lnkDelivery" target="_blank" href="#"><i class="soicon icon-localshipping"></i> 安排发货</a>
                </div>
            </div>
            <div class="row no-describe">
                <div class="col-lg-5">
                    <span>客户订单：</span><span>{{d.src_orderserial}}</span>
                    <br />
                    <span>订货日期：</span><span>{{d.orderdate}}</span>
                    <br />
                    <span>销售经办：</span><a class="People {{d.saler_id?'certificated':'no-certificated'}}" objid="{{d.saler_id}}"><img src='{{d.saler_headimg||'/UserFile/DefaultUserLogo-nocertificated.png'}}' />{{d.saler||d.src_saler}}</a>
                    <br />
                </div>
                <div class="col-lg-4 withLeftIndent">
                    <span>收&nbsp;货&nbsp;人：</span><span>{{d.src_consignee}}</span>
                    <br />
                    <span>联系方式：</span><span>{{d.src_consigneephone}}</span>
                    <br />
                    {{#if (d.urgent==true){ }}
                    <span>交货日期：</span><span class="urgent" title="交货日期已临近，请注意跟进">{{d.deliverydate}}<i class="icon-erroroutline"></i></span>
                    {{#}else{ }}
                    <span>交货日期：</span><span>{{d.deliverydate}}</span>
                    {{#} }}
                    <br />
                </div>
                <div class="col-lg-3">
                    <span>已发货：</span><span>{{d.totaldelivery||'-'}}{{d.dlvPercent}}</span>
                    <br />
                    <span>已入库：</span><span>{{d.totalstockin||'-'}}{{d.stockinPercent}}</span>
                    <br />
                </div>
            </div>
        </div>
    </div>
</script>
<script src="/LiberUI/Scripts/moment.js"></script>
<script src="/LiberUI/Scripts/bootstrap-datepicker.js"></script>
<script src="/LiberUI/Scripts/laytpl.js"></script>
<script>
    Delivery = {
        cnd: {
            status: "all",
            flag: "toDelivery",
            ordserial: null,
            client: null,
            ordDateStart: null,
            ordDateEnd:null,
            dlvDateStart: null,
            dlvDateEnd: null,
            asc:"dlvdate",
            page: 1,
            num:20
        },
        tplDlvItem: null,
        lstOrders: null,
        Query: function (recount) {
            Delivery.lstOrders.vl(null)
                               .update()
                               .Loading("正在加载...");

          if (recount) {
              Delivery.cnd.page = 1;
              $.getJSON("/Sale/CountOrders", Delivery.cnd, Delivery.onCountEnd);
          }
          $.getJSON("/Sale/QueryOrders", Delivery.cnd, Delivery.onGetOrdersEnd);
        },
        onGetOrdersEnd: function (rtn) {
            if (rtn.IsPositive) {
                Delivery.lstOrders.vl(rtn.Data["Orders"])
                                     .update()
                                     .show();
            }
        },
        makeOrdItemView: function ($li, od) {
            od.client_logo = od.client_logo || "/UserFile/DefaultCompanyLogo.gif";
            od.orderdate = new Date(od.src_orderdate || od.createtime).toString();
            od.updatetime = new Date(od.updatetime).toString();
            od.deliverydate = new Date(od.src_deliverydate || od.deliverydate).toString();

            if (Delivery.cnd.flag == 'toDelivery' || Delivery.cnd.flag == 'toStockIn') {
                od.urgent = daysBetween(new Date(od.src_deliverydate || od.deliverydate).toString(), new Date().toString()) < 5;
            }
            od.dlvPercent = od.totaldelivery ? ('<em>[' + (od.totaldelivery / od.amount).formatPercent(2) + ']</em>') : '';
            od.stockinPercent = od.totalstockin ? ('<em>[' + (od.totalstockin / od.amount).formatPercent(2) + ']</em>') : '';
            var itm = $(Delivery.tplOrdItem.render(od));
            //View.CheckAuthor(obj,$li);
            $li.append(itm.addClass("fladeInUp"));
            itm.find(".lnkDelivery").attr("href", "/Sale/DeliveryBillEdit?oid=" + od.idstr);
        },
        onCountEnd: function (rtn) {
            //根据统计结果添加计数标记
            if (rtn.IsPositive) {
                Delivery.paging.option("Total", rtn.Data.Total)
                                .option("CurrPage", 1)
                                .update();
            }
        },
        GoPage: function (pg) {
            Delivery.cnd.page = pg;
            Delivery.Query();
        }
    }

    $(function () {
        var navis = $("#slideNavi>li>a");
        for (var i = 0; i < navis.length; i++) {
            if (navis.eq(i).attr("href") == window.location.pathname) {
                navis.eq(i).addClass("current");
                break;
            }
        }

        $(".Searcher").appendTo(".searchboxWraper").fadeIn();

        Delivery.tplOrdItem = laytpl($("#tplOrderItem")[0].innerHTML);  //定义发货单列表项模板实例
        Delivery.lstOrders = new LiberUI.Lister("#dlv-lstOrders")
                                         .option("Slctble", false)
                                         .option("ContentRender", Delivery.makeOrdItemView);
        Delivery.paging = new LiberUI.Paging("#sal-lstOrders-Paging")
            .option("Row", 20)
            .option("BtnClick", Delivery.GoPage)
            .show();

        Delivery.Query(true);

        /*  16/7/28 更多筛选条件 */
        function fillSubmitData(data) {
            Delivery.cnd.ordserial = data.eq(0).vl().trim();
            Delivery.cnd.client = data.eq(1).vl().trim();
            Delivery.cnd.ordDateStart = data.eq(2).vl();
            Delivery.cnd.ordDateEnd = data.eq(3).vl();
            Delivery.cnd.dlvDateStart = data.eq(4).vl();
            Delivery.cnd.dlvDateEnd = data.eq(5).vl();
        }
        $('#more-filter-box .date-picker input').datepicker({
            autoclose: true,
            todayHighlight: true,
            format: 'yyyy-mm-dd'
        });
        $('#more-filter').on('click', function (e) {
            var status = $(this).hasClass('more-filter-open');
            if (status == true) {
                //如果已经展开，触发关闭按钮效果
                $('#more-filter-close').trigger('click');
                return;
            }

            //获取原始高度
            var box = $('#more-filter-box'), boxHeight = box.css('height', 'auto').height();

            //恢复0高度以便动画进行
            box.css('height', '0');

            $(this).addClass('more-filter-open');
            $('#more-filter-box').stop().animate({ height: boxHeight + 20 }, 500); // 20为 more-filter-box padding
        });
        $('#more-filter-close').on('click', function (e) {
            e.preventDefault();
            $('#more-filter-box').stop().animate({ height: 0 }, 500);
            $('#more-filter').removeClass('more-filter-open');

            //清空输入项
            var inputs = $('#more-filter-box').find('input');
            inputs.val('');
            fillSubmitData(inputs);
        });
        $('#more-filter-box').on('submit', function (e) {
            e.preventDefault();

            //筛选条件提交
            fillSubmitData($(this).find('input'));
            Delivery.Query(true);
        });
    })
</script>

